package com.app.controller;

import com.app.entity.DevUser;
import com.app.service.devuser.DevUserService;
import com.app.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author L
 * @Date 2021/4/2 11:14
 */
@Controller
@RequestMapping("/user")
public class DevUserController {

    @Autowired
    private DevUserService devUserService;

    /**
     * 登录验证
     * @param devUser
     * @param devPassword
     * @param session
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/login")
    public String login(String devUser, String devPassword, HttpSession session, HttpServletRequest request)throws Exception{
        DevUser user = devUserService.getLogin(devUser,devPassword);
        if (user != null){
            session.setAttribute(Constants.USER_SESSION,user);
            System.out.println(user.getDevName());
            return "redirect:/user/main";
        }else {
            request.setAttribute("error","用户名或者密码不正确");
            return "login";
        }
    }

    /**
     * 跳转main页面
     * @return
     */
    @RequestMapping("/main")
    public String main(){
        return "main";
    }


    /**
     * 退出登录
     * @param session
     * @return
     */
    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.removeAttribute(Constants.USER_SESSION);
        return "login";
    }

    /**
     * 跳转app维护页面
     * @return
     */
    @RequestMapping("/maintain")
    public String maintain(){
        return "maintain";
    }

    @RequestMapping("/show")
    public String show(){
        return "appList";
    }
    @RequestMapping("/add.do")
    public String add(){
        return "Appadd";
    }
}
